package cll;

import static java.lang.Math.random;

import org.apache.commons.math3.random.RandomDataImpl;
import static cll.Parameters.*;
public class TCell extends Cell {

	private boolean triggered = false;
	
	public TCell(Environment envt){
		environment = envt;
		type = Type.TCell;
		antigen = Antigen.getTargetAntigen();
		//System.out.println(antigen.toString());
		//nb_sites = 100;
		positionspeed = new PositionSpeed(random()*tailleGC, random()*tailleGC,0);
		rayon = rayonT;
		//CD38 = taux_cd38;
	}

	public void changeDirection() {
		if(Math.random() < dt/duree_persistence_deplacement_TC){
			Place myplace = environment.getPlace(positionspeed);
			
			double cosPrivilegie =myplace.getValeur19()*Math.cos(myplace.getDirection19());
			double sinPrivilegie =myplace.getValeur19()*Math.sin(myplace.getDirection19());
			
			if(triggered){
				cosPrivilegie +=myplace.getValeur13()*Math.cos(myplace.getDirection13());
				sinPrivilegie +=myplace.getValeur13()*Math.sin(myplace.getDirection13());
			}

				
			
			
			double randomDirection = (Math.random()-0.5)*2*Math.PI;
			
			double vx = cosPrivilegie + Math.cos(randomDirection);
			double vy = sinPrivilegie + Math.sin(randomDirection);
			
			double newDirection = Math.atan2(vy, vx);
			
			RandomDataImpl distribution = new RandomDataImpl();
			double valeur = distribution.nextPoisson(vitesse_Tcells);
			
			positionspeed.changeSpeed(newDirection,valeur );
		}
	}

	public Cell transforme() {
		return new DeadCell();
	}

	public void apoptosis() {
		
	}

	public void dealWithChemokine() {
		
	}

	

	@Override
	public void transition() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Cell Reproduction() {
		// TODO Auto-generated method stub
		return new DeadCell();
	}

	@Override
	public void interaction(Cell c) {
		if(c.type == Type.Centroblast){
			c.interaction(this);
		}
		if(c.type == Type.ReticularCell){
			triggered = true;
		}
	}

}
